package alg20250207;

import java.util.Arrays;

public class Text3 {
    public int triangleNumber(int[] nums) {
        int n = nums.length;
        Arrays.sort(nums);
        int ret = 0;
        for (int c = n - 1; c > 1; c--) {
            for (int a = 0, b = c - 1; a < b; ) {
                if(nums[a] + nums[b] > nums[c]){
                    ret += b - a;
                    b--;
                }else{
                    a++;
                }
            }
        }
        return ret;
    }
}
